/*
 * @Date: 2022-01-15 14:52:58
 * @LastEditors: LeeKing
 * @LastEditTime: 2022-01-15 15:58:37
 * @FilePath: \jikeyuan\src\components\AuthRoute\index.js
 */
import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom'
import { getToken } from 'utils/storage'

export default class AuthRoute extends Component {
  render () {
    const { component: Component, ...rest } = this.props
    return (
      <Route {...rest}
        render={(props) => {
          const token = getToken()
          if (token) return <Component {...props} />
          return <Redirect
            to={{
              pathname: '/login',
              state: {
                fromPath: props.location.pathname
              }
            }
            } />
        }} />
    )
  }
}
